package com.blyat.xsoft.gateway.security.refresher;

import com.google.common.base.Preconditions;
import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.security.oauth2.provider.ClientDetailsService;
import org.springframework.security.oauth2.provider.token.TokenStore;
import reactor.core.publisher.Mono;

/**
 * @Auther: syh
 * @Date: 2020/9/11
 * @Description:
 */
public abstract class AbstractReactiveTokenRefresher implements ReactiveTokenRefresher {
    private OAuth2AccessToken accessToken;
    private TokenStore tokenStore;
    private ClientDetailsService clientDetailsService;

    @Override
    public Mono<String> refresh() {
        Preconditions.checkNotNull(accessToken != null, "accessToken must be specify.");

        return doRefresh();
    }

    public abstract Mono<String> doRefresh();

    @Override
    public boolean shouldRefresh() {
        return false;
    }

    public void setAccessToken(OAuth2AccessToken accessToken) {
        this.accessToken = accessToken;
    }

    public OAuth2AccessToken getAccessToken() {
        return accessToken;
    }

    public TokenStore getTokenStore() {
        return tokenStore;
    }

    public void setTokenStore(TokenStore tokenStore) {
        this.tokenStore = tokenStore;
    }

    public void setClientService(ClientDetailsService clientService) {
        this.clientDetailsService = clientService;
    }

    public ClientDetailsService getClientService() {
        return clientDetailsService;
    }
}
